package com.study.ssm.resource;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;

import java.io.IOException;

/**
 * <pre>
 *     project name: SpringStudy
 *     author      : 李琼
 *     e-mail      : 1265137718@qq.com
 *     create time : 2017/9/16 上午1:13
 *     desc        : 描述--//MyResource TODO
 *     URL         : CSDN:http://blog.csdn.net/qq_22945151
 *                   GitHub:https://github.com/a1265137718
 *     Reference   ://
 *     modifier               :
 *     modification time      :
 *     modify remarks         :
 *
 *     @version: --//TODO
 * </pre>
 */


public class MyResource implements ApplicationContextAware {
    private ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public void getResources() throws IOException {
//        Resource resource = applicationContext.getResource("classpath:./resources/config.txt");
//        Resource resource = applicationContext.getResource("file:resources/config.txt");
//        Resource resource = applicationContext.getResource("url:http://www.baidu.com");
        //当没有前缀时,依赖于Application context,即默认为classpath加载方式
        Resource resource = applicationContext.getResource("/resources/config.txt");
        System.out.println(resource.getFilename());
        System.out.println(resource.contentLength());
    }
}
